import 'package:eleapp/pages/settings/langsetting.dart';
import 'package:eleapp/pages/settings/settings.dart';
import 'package:eleapp/pages/photo/evaluatedetail.dart';
import 'package:eleapp/pages/settings/themesetting.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

// 引入getx管理路由
import 'package:get/get.dart';

// 引入路由页面
import '../pages/tabs/tabs.dart';
import '../pages/login/login.dart';
import '../pages/index/tasklist.dart';
import '../pages/index/grouplist.dart';
import '../pages/photo/photo.dart';
import '../pages/photo/photopreview.dart';
import '../pages/personal/myinfo.dart';

// 引入路由中间件 相当于路由守卫
import '../middleware/tabsmiddleware.dart';

// 定义路由
final Map<String, Function> routes = {
  // 不带参
  '/': (context) => Tabs(),
  '/login': (context) => const Login(),

  // 带参
  // '/tasklist': (context, {arguments}) => Tasklist(arguments: arguments)
};

var onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  final String? name = settings.name;
  final Function? pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = CupertinoPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          CupertinoPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};

class AppPage {
  // 定义getx管理的路由数组
  static final appPage = [
    GetPage(
      name: '/',
      page: () => Tabs(),
      middlewares: [TabsMiddleWare()], // 利用中间件判断是否登录 没有登录跳转登录页
    ),
    GetPage(name: '/login', page: () => const Login()),

    // 需要传值cid 但是和不传值路由一样定义 取值：Get.arguments
    GetPage(
      name: '/tasklist',
      page: () => const Tasklist(),
      transition: Transition.cupertinoDialog, // 单独配置切换动画方式
    ),
    GetPage(
      name: '/grouplist',
      page: () => const Grouplist(),
      transition: Transition.cupertinoDialog, // 单独配置切换动画方式
    ),
    GetPage(
      name: '/photo',
      page: ({arguments}) => PhotoPage(arguments: arguments),
    ),
    GetPage(
      name: '/checkscore',
      page: () => const EvaluatePage(),
    ),
    GetPage(
      name: '/photopreview',
      page: () => const Photopreview(),
      transition: Transition.fadeIn,
    ),
    GetPage(
      name: '/myinfo',
      page: () => const Myinfo(),
    ),
    GetPage(
      name: '/settings',
      page: () => const Settings(),
    ),
    GetPage(
      name: '/langsetting',
      page: () => const LanguageSettingPage(),
    ),
    GetPage(
      name: '/themesetting',
      page: () => const ThemeSettingPage(),
    ),
  ];
}
